# -*- coding: utf-8 -*-
# @Time    : 2024/1/2  22:10
# @Author  : zhanghao
# @FileName: Rule.py
# @Software: PyCharm
"""
    Description:
        
"""
from domain.rename import Rename
from domain.match_content import MatchContent


class Rule:
    case_no_regex = "([（(][1-2]{1}[0-9]{3}[）)][京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[0-9]+[\\u4e00-\\u9fa5]+[0-9]+号(" \
                    "之一|之二|之三|之四|之五|之六|之七|之八|之九|之十|){1})"
    defendant_regex = "(被告|被申请人|被执行人){1}[：:]{1}([\\u4e00-\\u9fa5]+)[,，]{1}"

    type = ''
    keyword = ''
    ret_file_name = ''
    classify_id = ''
    rename: list[Rename] = []

    def __init__(self, type, keyword, ret_file_name, classify_id, grab_content: MatchContent):
        self.type = type
        self.keyword = keyword
        self.ret_file_name = ret_file_name
        self.classify_id = classify_id

        self.rename = []

        # 默认获取案号
        rename_obj = Rename('caseNo', 'regex', self.case_no_regex)
        self.rename.append(rename_obj)

        for content in grab_content.fields:
            if content == '被告':
                rename_obj = Rename('defendantName', 'regex', self.defendant_regex)
                self.rename.append(rename_obj)
            # elif content == '案号':
            #     rename_obj = Rename('caseNo', 'regex', self.case_no_regex)
            #     self.rename.append(rename_obj)

        if grab_content.words and len(grab_content.words) > 0:
            words = '#'.join(grab_content.words)
            rename_obj = Rename('keywords', 'keyword', words)
            self.rename.append(rename_obj)
